/*
 * @Description: 顶部导航栏
 * @Date: 2022-12-06 20:49:19
 * @Author: lizhiqiang
 */
import { CaretDownOutlined } from '@ant-design/icons';
import { Layout, Avatar, Dropdown, Space } from 'antd';
import React, { useEffect } from 'react';
import './index.module.scss'
import PersonContent from './PersonContent'
import Logo from '@/assets/img/logo.jpg'

const { Header } = Layout;
const MainHead: React.FC = () => {

  const userInfo = JSON.parse(localStorage.getItem("userInfo"))  //中台登录的用户信息
  // console.log(userInfo)

  const handleBack = () => {
     //如果对接的是中台cloudjsToken
    if(localStorage.getItem("cloudjsToken")){
      const env = import.meta.env.VITE_APP_ENV
      if(env==='test'||env==='dev'){
        window.location.href = 'https://admin-uat.028wlkj.com:1020/application-manage'
      }else {
        window.location.href = 'https://admin.028wlkj.com:1020/application-manage'
      }
      localStorage.removeItem("cloudjsToken")
      localStorage.removeItem("baseInfo") 
      localStorage.removeItem("menus") //清除权限菜单
      localStorage.removeItem("usedMenu") //清除权限菜单
      localStorage.removeItem("userInfo") //清除用户信息
      localStorage.removeItem("token") //清除用户信息
     }
  }



 
  return (
    <Header className="site-layout-background" style={ { padding: 0 } }>
      <div className='nav-left'>
        <div className='logoBox'>
           <img src={Logo} alt="" className='logoImg'/>
           <span className="title">支付运营 • 工作台</span>
        </div>
      </div>
      <div className='fr MR20 fz12 text-gray nav-right'>
        <div className='goBack' onClick={handleBack}>
          <img src="https://028wlkj.cn:30021/public/static/logos/home-stable.png" alt="" />
      </div>
        <Dropdown dropdownRender={ PersonContent }>
            <span onClick={e => e.preventDefault()}>
                <Space size={4}>
                <Avatar className='avatar' size="small">{userInfo?.userName.charAt(0)}</Avatar>
                <CaretDownOutlined style={{fontSize:8}} />
                </Space>
            </span>
        </Dropdown>
        </div>
    </Header>)
}
export default MainHead